package com.nsl.my_youlai.controller;

import com.nsl.my_youlai.common.result.Result;
import com.nsl.my_youlai.mystar.NslUtilFilePath;
import com.nsl.my_youlai.mystar.NslUtilHttpServletResponse;
import com.nsl.my_youlai.mystar.enums.NslEnumMime;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.UnsupportedEncodingException;

@Slf4j
@RestController
@RequestMapping("/api/v1/noAuth")
@RequiredArgsConstructor
public class NoAuthController {

    @GetMapping("/hello")
    public Result hello(){
        return Result.success("hello");
    }

    @GetMapping("/only_a/hello.txt")
    public  void onlyATag(HttpServletResponse httpServletResponse) throws UnsupportedEncodingException {
        String relativePath="download/hello.txt";
        File txtFile=new File(NslUtilFilePath.getFilePathBasedOnClassPath(relativePath));
        NslUtilHttpServletResponse.downloadFile(httpServletResponse,txtFile, NslEnumMime.ZIP_ZIP);
        //return Result.success("only a tag");
    }
}
